var e = getApp();

Page({
    data: {
        language: "",
        refundMoney: "",
        address: [],
        checked: {},
        options: [],
        express: "",
        expressCode: "",
        expressSN: "",
        popupVisible: !1,
        orderId: "",
        id: "5",
        order_status: 0,
        check_status: "",
        checkedindex: 0
    },
    onLoad: function(e) {
        e.id && this.setData({
            id: e.id
        }), this.applyData();
    },
    onReady: function() {
        var e = wx.getStorageSync("langIndex");
        this.setData({
            language: e.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    applyData: function() {
        var t = this, s = e.getNetAddresss("plugin.lease-toy.api.retreat.return.index");
        s += "&order_id=" + this.data.id, e._getNetWork({
            url: s,
            success: function(s) {
                var a = s.data;
                if (1 == a.result) {
                    var n = a.data.lease_order;
                    t.setData({
                        refundMoney: n.deposit_total,
                        orderId: n.order_id,
                        id: n.id,
                        order_status: n.return_status,
                        check_status: n.return_name
                    }), e._isTextEmpty(a.data.return_address) ? wx.showToast({
                        title: "请填写退还地址",
                        icon: "none",
                        duration: 1500,
                        success: function() {
                            setTimeout(function() {
                                wx.navigateBack({
                                    delta: 1
                                });
                            }, 1500);
                        }
                    }) : (t.setData({
                        address: a.data.return_address
                    }), t.data.address.forEach(function(e) {
                        1 == e.is_default && t.setData({
                            checked: e
                        });
                    })), t.setData({
                        options: a.data.express_companies
                    });
                } else wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    getAddress: function() {
        var t = e.getNetAddresss("plugin.lease-toy.api.return-address.index");
        e._getNetWork({
            url: t,
            success: function(e) {
                var t = e.data;
                1 == t.result && console.log(t.msg);
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    getExpress: function() {
        var t = this, s = e.getNetAddresss("dispatch.express-list");
        e._getNetWork({
            url: s,
            success: function(e) {
                var s = e.data;
                1 == s.result && t.setData({
                    options: s.data.express_companies
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    chooseAddress: function(e) {
        var t = e.detail;
        this.setData({
            checkedindex: t,
            checked: this.data.address[t]
        });
    },
    expressSNinp: function(e) {
        var t = e.detail.value;
        console.log(t), this.setData({
            expressSN: t
        });
    },
    expressShow: function() {
        this.setData({
            popupVisible: !0
        });
    },
    expressClose: function() {
        this.setData({
            popupVisible: !1
        });
    },
    expressChoose: function(e) {
        var t = e.currentTarget.dataset.item;
        this.initExpress(), this.setData({
            express: t.name,
            expressCode: t.value,
            popupVisible: !1
        });
    },
    initExpress: function() {
        this.setData({
            express: "",
            expressCode: ""
        });
    },
    submit: function() {
        if (e._isTextEmpty(this.data.checked.address)) wx.showToast({
            icon: "none",
            title: "请选择归还地址",
            duration: 1500
        }); else if (e._isTextEmpty(this.data.express)) wx.showToast({
            icon: "none",
            title: "请选择退还快递",
            duration: 1500
        }); else if (e._isTextEmpty(this.data.expressCode)) wx.showToast({
            icon: "none",
            title: "快递code不能为空",
            duration: 1500
        }); else if (e._isTextEmpty(this.data.expressSN)) wx.showToast({
            icon: "none",
            title: "快递编号不能为空",
            duration: 1500
        }); else {
            var t = e.getNetAddresss("plugin.lease-toy.api.retreat.return.submit-return");
            t += "&order_id=" + this.data.orderId, t += "&lease_id=" + this.data.id, t += "&express_code=" + this.data.expressCode, 
            t += "&express_company_name=" + this.data.express, t += "&express_sn=" + this.data.expressSN, 
            t += "&address=" + this.data.checked.address, t += "&mobile=" + this.data.checked.mobile, 
            t += "&realname=" + this.data.checked.contact_name, e._getNetWork({
                url: t,
                success: function(e) {
                    1 == e.data.result ? wx.showToast({
                        title: "提交成功",
                        icon: "none",
                        duration: 1500,
                        success: function() {
                            setTimeout(function() {
                                wx.navigateBack({
                                    delta: 1
                                });
                            }, 1500);
                        }
                    }) : wx.showToast({
                        title: "提交失败",
                        icon: "none",
                        duration: 1500,
                        success: function() {
                            setTimeout(function() {
                                wx.navigateBack({
                                    delta: 1
                                });
                            }, 1500);
                        }
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        }
    }
});